﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:Imagin.Controls.Common"
    xmlns:Common.Data.Converters="clr-namespace:Imagin.Common.Data.Converters;assembly=Imagin.Common">
    <Common.Data.Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    <Common.Data.Converters:StringToVisibilityConverter x:Key="StringToVisibilityConverter"/>

    <Style x:Key="{x:Type local:EditableLabel}" TargetType="{x:Type local:EditableLabel}">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:EditableLabel}">
                    <Grid>
                        <Grid Visibility="{TemplateBinding IsEditable, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=Inverted}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock 
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                Margin="{TemplateBinding Padding}"
                                Text="{Binding Text, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            <local:MaskedButton
                                Grid.Column="1"
                                x:Name="PART_Button"
                                HorizontalAlignment="{TemplateBinding ButtonHorizontalAlignment}"
                                Source="pack://application:,,,/Imagin.Controls.Common;component/Images/Pencil.png"
                                Margin="5,0,0,0"
                                Visibility="{TemplateBinding ShowButton, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                        </Grid>
                        <Border 
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Background="{TemplateBinding Background}" 
                            BorderBrush="{TemplateBinding BorderBrush}"
                            Visibility="{TemplateBinding IsEditable, Converter={StaticResource BooleanToVisibilityConverter}}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <TextBlock 
                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                    Margin="{TemplateBinding Padding}"
                                    Style="{TemplateBinding PlaceholderStyle}"
                                    Text="{TemplateBinding Placeholder}"
                                    TextTrimming="{TemplateBinding TextTrimming}"
                                    TextWrapping="{TemplateBinding TextWrapping}"
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                    Visibility="{TemplateBinding Text, Converter={StaticResource StringToVisibilityConverter}, ConverterParameter=Inverted}"/>
                                <ScrollViewer 
                                    x:Name="PART_ContentHost" 
                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                    Padding="{TemplateBinding Padding}"
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                <Grid Grid.Column="1" Visibility="{TemplateBinding CanUserClear, Converter={StaticResource BooleanToVisibilityConverter}}">
                                    <local:MaskedButton
                                        x:Name="PART_ClearButton"
                                        Source="pack://application:,,,/Imagin.Controls.Common;component/Images/XRound.png"
                                        Margin="5,0,0,0"
                                        Visibility="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource StringToVisibilityConverter}}"/>
                                </Grid>
                            </Grid>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsEditable" Value="True">
                <Setter Property="Cursor" Value="IBeam"/>
            </Trigger>
            <Trigger Property="IsEditable" Value="False">
                <Setter Property="Cursor" Value="Hand"/>
            </Trigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>